package cn.glutnn.auth.domain.service.impl;

import cn.glutnn.auth.common.enums.IsDeletedFlagEnum;
import cn.glutnn.auth.domain.convert.AuthRolePermissionConverter;
import cn.glutnn.auth.domain.entity.AuthPermissionBO;
import cn.glutnn.auth.domain.entity.AuthRolePermissionBO;
import cn.glutnn.auth.domain.service.AuthRolePermissionDomainService;
import cn.glutnn.auth.infra.basic.entity.AuthRolePermission;
import cn.glutnn.auth.infra.basic.service.AuthRolePermissionService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.LinkedList;

/**
 * Author:   msh
 * Date:     2025/1/14 下午1:59
 * Description:
 */

@Service
@Slf4j
public class AuthRolePermissionDomainServiceImpl implements AuthRolePermissionDomainService {
    @Resource
    private AuthRolePermissionService authRolePermissionService;

    @Override
    public Boolean add(AuthRolePermissionBO authRolePermissionBO) {
        LinkedList<AuthRolePermission> authRolePermissions = new LinkedList<>();
        authRolePermissionBO.getPermissionIds().forEach(permissionId -> {
            AuthRolePermission authRolePermission = new AuthRolePermission();
            authRolePermission.setRoleId(authRolePermissionBO.getRoleId());
            authRolePermission.setPermissionId(permissionId);
            authRolePermission.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
            authRolePermissions.add(authRolePermission);
        });
        return authRolePermissionService.saveBatch(authRolePermissions);
    }
}
